/*******************************************************************************
 * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Marc R. Hoffmann - initial API and implementation
 *
 *******************************************************************************/
package org.jacoco.cli.internal;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;

import org.jacoco.core.tools.ExecDumpClient;
import org.jacoco.core.tools.ExecFileLoader;

/**
 * 调试生成覆盖exec文件
 *
 * @author liaozhiyong
 *
 */
public class CoverDumpApiTestMain {

	/**
	 * exec文件
	 */
	private File destfile;

	public static void main(String[] args) {
		String address = "localhost";
		int port = 6300;
		boolean reset = false;
		int retrycount = 10;
		// 覆盖率的exec文件地址
		File destfile = new File(
				"D:\\workblue\\jacoco\\lib4\\debug\\demo111.exec");

		try {
			ExecDumpClient client = new ExecDumpClient() {
				@Override
				protected void onConnecting(final InetAddress address,
						final int port) {
					System.out.println(
							String.format("[INFO] Connecting to %s:%s.%n",
									address, Integer.valueOf(port)));
				}

				@Override
				protected void onConnectionFailure(
						final IOException exception) {
					System.out.println(String.format("[WARN] %s.%n",
							exception.getMessage()));
				}
			};
			client.setReset(reset);
			client.setRetryCount(retrycount);

			final ExecFileLoader loader = client.dump(address, port);
			System.out.println(
					String.format("[INFO] Writing execution data to %s.%n",
							destfile.getAbsolutePath()));
			loader.save(destfile, true);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
